#include <iostream>
using namespace std;

int n;
int m;
char grid[405][405];
bool v[405][405];
int cnt;
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, -1, 0, 1};

bool ok(int r, int c) {
    if (r < 0 || r >= n || c < 0 || c >= m) return 0;
    return 1;
}

void dfs(int r, int c) {
    v[r][c] = 1;
    for (int i = 0; i < 4; i++) {
        int fr = r + dr[i];
        int fc = c + dc[i];
        if(!ok(fr,fc)) continue;
        if(grid[fr][fc] == '0') continue;
        if(v[fr][fc]) continue;
        dfs(fr,fc);
    }
    return;
}

int main() {
    cin >> n;
    cin >> m;
    string s;
    for (int i = 0; i < n; i++) {
        cin >> s;
        for (int j = 0; j < m; j++) grid[i][j] = s[j];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (v[i][j]) continue;
            if (grid[i][j] == '0') continue;
            dfs(i, j);
            cnt+=1;
        }
    }
    cout << cnt << endl;
}